package com.leyou.search.controller;

import com.leyou.common.vo.PageResultVO;
import com.leyou.search.dto.GoodsDTO;
import com.leyou.search.dto.SearchRequest;
import com.leyou.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author xiuer
 * @description 搜索微服务控制层
 * @create 2019/7/1 21:06
 */
@RestController
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 根据搜索栏关键字搜索分页查询-----页面下具体数据展示
     * @param searchRequest 请求参数对象
     * @return
     */
    @PostMapping("page")
    public ResponseEntity<PageResultVO<GoodsDTO>>searchGoods(@RequestBody SearchRequest searchRequest) {
        return ResponseEntity.ok(searchService.searchGoods(searchRequest));
    }

    /**
     * 导航栏下过滤选项展示
     */
    @PostMapping("filter")
    public ResponseEntity<Map<String, List<?>>> searchFilterGoods(@RequestBody SearchRequest request) {
        return ResponseEntity.ok(searchService.searchFilterGoods(request));
    }
}
